<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    function _fetch() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          reject('err')
        }, 1000)
      })
    }

    function load (onError) {
      const p = _fetch()
      return p.catch((err) => {
        return new Promise((resolve, reject) => {
          const retry = () => resolve(load(onError))
          const fail = () => reject(err)
          onError(retry, fail)
        })
      })
    }

    load((retry, fail) => {
      console.log(retry, 'kkk')
      retry()
      // fail()
    })
      .then((res) => {
        console.log(res)
      })
  </script>
</body>
</html>